#include "GiaoDich.h"
//#ifndef DEFINE_G_GIAODICH
//#define DEFINE_G_GIAODICH
//static GiaoDich gGiaoDich;
//#endif
void GiaoDich::AddGiaoDich(int type, int soTien)
{
	tGiaoDich giaoDich;
	tNode node;
	switch(type)
	{
		case 1://chuyen khoan
			strcpy(giaoDich.tenGiaoDich,"Chuyen khoan");
			break;
		case 2://In hoa don
			strcpy(giaoDich.tenGiaoDich,"In hoa don");
			break;
		case 3://In sao ke
			strcpy(giaoDich.tenGiaoDich,"In sao ke");
			break;
			strcpy(giaoDich.tenGiaoDich,"Rut tien");
		case 4://Rut tien
		default:
			break;
	};
	giaoDich.soTienGiaoDich = soTien;
	giaoDich.soDuTrongTK = 0;
	strcpy(giaoDich.thoiGianGiaoDich,"2013");
	//giaoDich.thoiGianGiaoDich = System.DateTime.Now;
	tNode *p;
	p = TaoGiaoDich(giaoDich);
	if(listGD.head==NULL)
        listGD.head = listGD.tail=p;
    else
    {
        p->next = listGD.head;
        listGD.head=p;
    }
}
tNode *GiaoDich::TaoGiaoDich(tGiaoDich giaoDich)
{
	tNode *p;
    p=new tNode;
    if(p==NULL)
    {
        //cout<<"Khong cap phat duoc bo nho ";
        exit(0);
    }
    p->giaoDich = giaoDich;
    p->next=NULL;
}

//tra ve N giao dich cuoi neu n >0
//tra ve All giao dich neu n = 0
void GiaoDich::GiaoDichCuoi(int n, tListGiaoDich &list)
{
	int i =0;
	if (n==0)
	{
		list.head = listGD.head;
		list.tail = listGD.tail;
	}
	else
	{
		list.head = list.tail = listGD.head;
		i++;
		while (i<n || list.tail->next != NULL)
		{
			list.tail = list.tail->next;
			i ++;
		}
	}
}
